use strict;
use warnings;

package Gravity::Model::Person;
use Jifty::DBI::Schema;

use Gravity::Record schema {

    column first_name =>
        type is 'text',
        label is 'First Name',
        is mandatory,
    ;

    column last_name =>
        type is 'text',
        label is 'Last Name',
        is mandatory,
    ;

    column custodians =>
        references Gravity::Model::CustodianCollection
            by 'person',
    ;

};

sub since { '0.0.2' }

sub name {
    my $self = shift;
    $self->last_name.', '.$self->first_name;
}

sub after_create {
    my ( $self, $id ) = @_;

    # load newly created matter if it exists
    return unless $$id;
    $self->load($$id);

    my $tag = Gravity::Model::Tag->new;
    $tag->create(name => $self->first_name.$self->last_name);

    return 1;
}

1;

